"""
序列化器--外键关系
"""
from rest_framework import serializers
from .models import Employee, Salary

class EmpSerializer(serializers.ModelSerializer):
    class Meta:
        model = Employee
        fields = '__all__'

    # salaries必须和Model类中的属性对应
    salaries = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
"""
read_only=True 表示salaries字段仅用于读取，也就是仅用于序列化的时候
many=True，因为一个员工可以有多条工资记录
"""

# 只读
# salaries =serializers.PrimaryKeyRelatedField(queryset=Salary.objects.all(), many=True)
# 可读写

class SalarySerializer(serializers.ModelSerializer):
    class Meta:
        model = Salary
        fields = '__all__'